package ex4;

/**
 * @author: knowno
 * @create: 2024-09-06 14:11
 * @Version 1.0
 **/
public class TestBoy {
    public static void main(String[] args) throws CloneNotSupportedException {

        Boy boy = new Boy("小白", 20);
        //不同的是，boy中多了girl属性->关联
        Girl girl = new Girl("小黑", 20);
        boy.setGirl(girl);
        System.out.println("********克隆之前***************");
        System.out.println(boy);
        System.out.println(boy.getGirl());

        Boy boy1 = (Boy) boy.clone();
        System.out.println("********克隆之后***************");
        System.out.println("**********boy*******************");
        System.out.println(boy);
        System.out.println(boy.getGirl());
        System.out.println("**********boy1*******************");
        System.out.println(boy1);
        System.out.println(boy1.getGirl());
        //修改了克隆出来的那个小白的女朋友的信息
        boy1.getGirl().setName("小黄");
        System.out.println("**********修改了boy1的女朋友信息*******************");
        System.out.println("**********boy*******************");
        System.out.println(boy);
        System.out.println(boy.getGirl());
        System.out.println("**********boy1*******************");
        System.out.println(boy1);
        System.out.println(boy1.getGirl());




    }
}
